import classnames from 'classnames'

import Icon from '@/components/Icon'

import { ArticlesItem } from '@/types/data.d.'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import styles from './index.module.scss'

// 国际化
import { Image } from 'antd-mobile'
import 'dayjs/locale/zh-cn'
dayjs.locale('zh-cn')
// 添加插件
dayjs.extend(relativeTime)

type Props = {
  /**
   * 0 表示无图
   * 1 表示单图
   * 3 表示三图
   */
  type: 0 | 1 | 3
  item: ArticlesItem
}

const ArticleItem = ({ type, item }: Props) => {
  return (
    <div className={styles.root}>
      <div
        className={classnames(
          'article-content',
          type === 3 && 't3',
          type === 0 && 'none-mt'
        )}>
        <h3>{item.title}</h3>
        {type !== 0 && (
          <div className="article-imgs">
            {item.cover.images.map((i, index) => (
              <div className="article-img-wrapper" key={index}>
                <Image
                  src={i}
                  alt=""
                  lazy={true}
                  placeholder
                  style={{
                    '--width': '110px',
                    '--height': '75px',
                    borderRadius: 4,
                  }}
                />
              </div>
            ))}
          </div>
        )}
      </div>
      <div className={classnames('article-info', type === 0 && 'none-mt')}>
        <span>{item.aut_name}</span>
        <span>{item.comm_count} 评论</span>
        <span>{dayjs().to(dayjs(item.pubdate))} </span>
        <span className="close">
          <Icon icon="iconbtn_essay_close" />
        </span>
      </div>
    </div>
  )
}

export default ArticleItem
